import {request} from 'umi'

/**
 * 分页获取菜单
 * @param current
 * @param page_size
 */
export function getMenus(current?: number, page_size?: number) {
  return request<ABIS.Pagination<ABIS.MenuVO>>(
    '/api/menus/list',
    {
      params: {
        current,
        page_size
      }
    }
  )
}

/**
 * 根据 id 获取菜单
 * @param id
 */
export function getMenu(id: number) {
  return request<ABIS.Result<ABIS.Menu>>(
    '/api/menus/get',
    {
      params: {
        id
      }
    }
  )
}

/**
 * 树形获取菜单
 */
export function getMenuTree() {
  return request<ABIS.ResultList<ABIS.MenuTree>>(
    '/api/menus/tree'
  )
}

/**
 * 添加菜单
 *
 * @param name
 * @param path
 * @param icon
 * @param parent_id
 * @param weight
 */
export function addMenu(name: string, path: string, icon?: string, parent_id?: number, weight?: number) {
  return request<ABIS.Result<boolean | string>>(
    '/api/menus/add',
    {
      method: 'POST',
      data: {
        name,
        path,
        icon,
        parent_id,
        weight
      },
      requestType: 'form'
    }
  )
}

/**
 * 编辑菜单
 * @param id
 * @param name
 * @param path
 * @param icon
 * @param parent_id
 * @param weight
 */
export function editMenuById(id: number, name?: string, path?: string, icon?: string, parent_id?: number, weight?: number) {
  return request<ABIS.Result<boolean | string>>(
    '/api/menus/edit',
    {
      method: 'PUT',
      data: {
        id,
        name,
        path,
        icon,
        parent_id,
        weight
      },
      requestType: 'form'
    }
  )
}

/**
 * 删除菜单
 * @param ids
 */
export function deleteMenuById(ids: number[]) {
  return request(
    '/api/menus/del',
    {
      method: 'DELETE',
      data: {
        ids
      },
      requestType: 'form'
    }
  )
}
